package thread.noteplus;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

@SuppressWarnings("all")
public class Client{
    private Socket socket;
    public Client(){
        try {
            System.out.println("正在链接");
            socket= new Socket("yjpyjp",8080);//127.0.0.1 //176.17.9.39
            System.out.println("连接成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void start(){
        try {
            OutputStream outputStream = socket.getOutputStream();
            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
            BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
            PrintWriter printWriter = new PrintWriter(bufferedWriter,true);
            Scanner scanner = new Scanner(System.in);
            while (true){
                System.out.printf("发送消息:");
                String next = scanner.nextLine();
                if ("exit".equals(next)){
                    break;
                }
                printWriter.println(next);

            }
        } catch (IOException e) {
            e.printStackTrace();
        }  finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }

    public static void main(String[] args){
        Client client = new Client();
        client.start();

    }





}
